#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
//https://www.luogu.com.cn/problem/P1060
using namespace std;
const int N = 3e4 + 10, M = 30;


int n, m;
int f[N];
int a[N], w[N];

int main()
{
	cin >> n >> m;
	for (int i = 1; i <= m; ++i)
	{
		cin >> a[i] >> w[i];
		w[i] *= a[i];
	}



	for(int k = 1 ; k <= m ; ++k)
		for (int i = n; i >= a[k]; --i)
		{
			f[i] = max(f[i - a[k]] + w[k], f[i]);
		}

	cout << f[n] << endl;

	return 0;
}